//
//  ECUITVCell_DetailMaterial.m
//  Edu_iOS
//
//  Created by yanyan on 2017/9/21.
//  Copyright © 2017年 yanyan. All rights reserved.
//

#import "ECUITVCell_DetailMaterial.h"
@implementation ECModel_DetailMaterial
@end
@interface ECUITVCell_DetailMaterial()
@property(nonatomic,strong)UIView *centerView;
@property(nonatomic,strong)UIImageView *tagView;
@property(nonatomic,strong)UIButton *downloadView;
@property(nonatomic,strong)UILabel *titleLabel;
@property(nonatomic,strong)UILabel *sizeLabel;
@end
@implementation ECUITVCell_DetailMaterial
- (void)addSubviews
{
    CGFloat hPadding = 10 * kPercentage;
    CGFloat vPadding = 10 * kPercentage;
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    [super addSubviews];
    _tagView = [[UIImageView alloc]init];
    [self.contentView addSubview:_tagView];
    _centerView = [[UIView alloc]init];
    _centerView.backgroundColor = [UIColor colorWithHexString:@"#f2f5f6"];
    _centerView.layer.cornerRadius = 5;
    _centerView.layer.masksToBounds = YES;
    [self.contentView addSubview:_centerView];
    [self.contentView addSubview:_tagView];

    _titleLabel = [[UILabel alloc]init];
    _titleLabel.font = [UIFont systemFontOfSize:13 * kPercentage];
    _titleLabel.textColor = [UIColor colorWithHexString:@"#293039"];
    [self.centerView addSubview:_titleLabel];
    
    _sizeLabel = [[UILabel alloc]init];
    _sizeLabel.textColor = [UIColor colorWithHexString:@"#73757b"];
    _sizeLabel.font = [UIFont systemFontOfSize:10 * kPercentage];
    [self.centerView addSubview:_sizeLabel];
    _downloadView = [UIButton buttonWithType:UIButtonTypeCustom];
    [_downloadView setImage:[UIImage imageNamed:@"materialTag_Download"] forState:UIControlStateNormal];
    [self.centerView addSubview:_downloadView];
    WeakSelf(weakSelf);
    [_tagView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.contentView).offset(hPadding);
        make.top.equalTo(weakSelf.contentView).offset(hPadding);
        make.width.equalTo(@(47 * kPercentage));
        make.height.equalTo(weakSelf.tagView.mas_width);
    }];
    
    [_centerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.tagView.mas_centerX);
        make.top.equalTo(weakSelf.tagView.mas_centerY).offset(-vPadding);
        make.right.equalTo(weakSelf.contentView).offset(-hPadding);
        make.bottom.equalTo(weakSelf.contentView);
    }];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.tagView.mas_right).offset(5);
        make.top.equalTo(weakSelf.centerView);
        make.height.equalTo(weakSelf.centerView).multipliedBy(0.5);
    }];
    [_sizeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.titleLabel);
        make.top.equalTo(weakSelf.titleLabel.mas_bottom);
    }];
    [_downloadView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(weakSelf.centerView).offset(-5);
        make.centerY.equalTo(weakSelf.centerView .mas_centerY);
        make.width.equalTo(@(20 * 1.1));
        make.height.equalTo(@(20));
        
    }];
    
}
- (void)setObject:(id)object
{
    [super setObject:object];
    ECModel_DetailMaterial *mo = object;
    self.titleLabel.text = mo.name;
    self.sizeLabel.text = mo.size;
    if ([mo.tag isEqualToString:@"ppt"]) {
        self.tagView.image = [UIImage imageNamed:@"materialTag_PPT"];
   
    }
    if ([mo.tag isEqualToString:@"pdf"]) {
        self.tagView.image = [UIImage imageNamed:@"materialTag_PDF"];
        
    }
    if ([mo.tag isEqualToString:@"word"]) {
        self.tagView.image = [UIImage imageNamed:@"materialTag_Word"];
        
    }
    if ([mo.tag isEqualToString:@"excel"]) {
        self.tagView.image = [UIImage imageNamed:@"materialTag_Excel"];
        
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
